#include "DeductionView.h"

#include <boost/bind.hpp>
#include "../../models/network/CardViewModel.h"

using namespace Views::Client;
using namespace Views::Helpers::Graphic::Deduction;
using namespace Utils;

DeductionView::DeductionView(Utils::GUI::Form* form, Domain::Network::GameClient* client, Cards::CardsCollection cards):
Graphic::DeductionView(form), client(client), cards(cards)
{
}

void DeductionView::openPickCardDialog(Players::Player* player, Cards::CardSet&)
{
	current_player = player;
	client->doOnReceiveData(Domain::Configuration::Network::DEDUCTION_PICK_CARD,
		boost::bind(&DeductionView::onDeductedCardPick, this, _1));
}

void DeductionView::onSearchedCardsPick(Cards::PlayerCard* player_card, Cards::WeaponCard* weapon_card)
{
	sf::Packet packet;
	Views::Models::Network::CardViewModel cvm(player_card);
	packet << cvm;
	cvm.card = weapon_card;
	packet << cvm;
	client->send(Domain::Configuration::Network::DEDUCTION_SEARCHED_CARDS, packet);

	Graphic::DeductionView::onSearchedCardsPick(player_card, weapon_card);
}

void DeductionView::onDeductedCardPick(sf::Packet packet)
{
	Views::Models::Network::CardViewModel cvm(cards);
	packet >> cvm;
	Graphic::DeductionView::onDeductedCardPick(cvm.card);
}

void DeductionView::onDeductedCardsDialogClose()
{
	client->send(Domain::Configuration::Network::DEDUCTION_CARD_SHOW, sf::Packet());
	Graphic::DeductionView::onDeductedCardsDialogClose();
}

